class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int left=0;
        int right=0;
        vector<int> hashp(26, 0);
        vector<int> hashs(26, 0);
        vector<int> ret;
        int ns=s.size();
        int np=p.size();
         for (char c : p) 
        {        
            hashp[c - 'a']++;
        }
        if (ns < np) return ret; 
        while(right<ns)
        {
            hashs[s[right]-'a']++;
           
            if(right-left+1>np)
            {
                hashs[s[left++]-'a']--;
            }
            if(right-left+1==np)
            {
                if(hashs==hashp)
                    ret.push_back(left);
            }
            right++;
        }
        return ret;
    }
};
